package org.example.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Service;


@Service
public class ClientService {

    // ribbon 的负载均衡工具
    @Autowired
    private LoadBalancerClient  loadBalancerClient;

    public String client(){
        ServiceInstance si = loadBalancerClient.choose("myProject");//不区分大小写

        System.out.println(si.getHost());
        System.out.println(si.getServiceId());
        System.out.println(si.getUri());

        return si.getUri().toString();
    }

}
